package combine

import "sort"

func combine(s, e, m int) [][]int {
	if m > e-s+1 {
		return nil
	}
	if e-s+1 <= 0 || m <= 0 {
		return nil
	}
	var result [][]int
	if m == 1 {
		for i := s; i <= e; i++ {
			result = append(result, []int{i})
		}
		return result
	}
	if m > 1 {
		for j := s + 1; j <= e-m+2; j++ {
			//fmt.Println(":",j,e)
			r := combine(j, e, m-1)
			if r == nil {
				return nil
			}
			for z := range r {
				r[z] = append(r[z], j-1)
				sort.Ints(r[z])
			}
			result = append(result, r...)
			//fmt.Println(result)
		}
		return result
	}
	return result
}
